<?php
include __DIR__.'/WeiXin.php';
if(!isset($_GET['state'])||$_GET['state']!=$_SESSION['weixin_state']||!isset($_GET['code'])) die('非法请求'.var_export($_SESSION,true));
$setting=$config['oauth_login']['weixin']['setting'];
$weiXin=new WeiXin($setting['appid'],$setting['secret']);
$userInfo=$weiXin->getUserInfo($weiXin->getAccessToken($_GET['code']));
//授权用户信息
$_SESSION['oauth_info']=array(
    'oauth_form'=>'weixin',//授权来源
    'oauth_info'=>$userInfo,//授权信息
    'oauth_user_name'=>$userInfo['nickname'],//授权平台用户名或昵称
    'oauth_user_avatar'=>$userInfo['headimgurl'],//授权平台用户头像
    'openid'=>$userInfo['openid'],//用户唯一标识
    'unionid'=>$userInfo['unionid'],//开放平台应用唯一id，用于微信
);

//转到注册登录页面
@header('location: '.SHOP_SITE_URL.'/index.php?act=login');